package com.itheima.tcp;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/*
tcp 服务端
 */
public class ServerDemo {

    public static void main(String[] args) throws IOException {
        //创建服务端对象
        ServerSocket ss = new ServerSocket(9999);
        //建立连接  获取socket 对象
        Socket socket = ss.accept();
        //获取输入流
        InputStream is = socket.getInputStream();
        //读数据
        /*int b;
        while ((b=is.read())!=-1){
            System.out.print((char)b);
        }*/
        byte[] bytes=new byte[1024];
        int len;
        while ((len=is.read(bytes))!=-1){
            System.out.println(new String(bytes,0,len));
        }
        //释放资源
        socket.close();
        ss.close();



    }
}
